﻿<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:System.Net.XMPP;assembly=xmpp"
    xmlns:comp="clr-namespace:System.ComponentModel;assembly=WindowsBase"
    xmlns:dat="clr-namespace:System.Windows.Data;assembly=PresentationFramework"
    xmlns:extra="clr-namespace:WPFImageWindows;assembly=WPFImageWindows"
    xmlns:local="clr-namespace:WPFXMPPClient"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" x:Class="WPFXMPPClient.MainWindow"
    AllowsTransparency="True" WindowStyle="None"  SizeChanged="Window_SizeChanged"
    MouseDown="Window_MouseDown" ResizeMode="CanResizeWithGrip"
     Title="XMPP Chat Client" Loaded="SurfaceWindow_Loaded"
        GotFocus="Window_GotFocus"
    Background="Transparent" mc:Ignorable="d" 
        Height="600" Width="452">

    <Window.Resources>

        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
        
        <Storyboard x:Key="StoryBoardMakeBigGlobe">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="ButtonGlobe">
                <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="1.6"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="ButtonGlobe">
                <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="1.6"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>

        <Storyboard x:Key="StoryBoardMakeBigSpeaker">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="ButtonStartAudio">
                <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="1.6"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="ButtonStartAudio">
                <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="1.6"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>

        <Storyboard x:Key="StoryBoardMakeBigChat">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="ToggleButtonChat">
                <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="1.6"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="ToggleButtonChat">
                <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="1.6"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
        
        <DataTemplate x:Key="ChatMessageTemplate">
            <Grid Background="{x:Null}"  HorizontalAlignment="Stretch" x:Name="MainChatGrid">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="74" />
                    <ColumnDefinition Width="300*" />
                </Grid.ColumnDefinitions>
                    
                <Grid.RowDefinitions>
                    <RowDefinition Height="50*" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>


                <Grid.Triggers>
                    <EventTrigger RoutedEvent="Mouse.MouseEnter" SourceName="ButtonGlobe">
                        <BeginStoryboard x:Name="StoryBoardMakeBigGlobe_BeginStoryboard" Storyboard="{StaticResource StoryBoardMakeBigGlobe}"/>
                    </EventTrigger>
                    <EventTrigger RoutedEvent="Mouse.MouseLeave" SourceName="ButtonGlobe">
                        <StopStoryboard BeginStoryboardName="StoryBoardMakeBigGlobe_BeginStoryboard"/>
                    </EventTrigger>
                    
                    <EventTrigger RoutedEvent="Mouse.MouseEnter" SourceName="ButtonStartAudio">
                        <BeginStoryboard x:Name="StoryBoardMakeBigSpeaker_BeginStoryboard" Storyboard="{StaticResource StoryBoardMakeBigSpeaker}"/>
                    </EventTrigger>
                    <EventTrigger RoutedEvent="Mouse.MouseLeave" SourceName="ButtonStartAudio">
                        <StopStoryboard BeginStoryboardName="StoryBoardMakeBigSpeaker_BeginStoryboard"/>
                    </EventTrigger>

                    <EventTrigger RoutedEvent="Mouse.MouseEnter" SourceName="ToggleButtonChat">
                        <BeginStoryboard x:Name="StoryBoardMakeBigChat_BeginStoryboard" Storyboard="{StaticResource StoryBoardMakeBigChat}"/>
                    </EventTrigger>
                    <EventTrigger RoutedEvent="Mouse.MouseLeave" SourceName="ToggleButtonChat">
                        <StopStoryboard BeginStoryboardName="StoryBoardMakeBigChat_BeginStoryboard"/>
                    </EventTrigger>
                </Grid.Triggers>
                
                <Rectangle VerticalAlignment="Top" Stroke="{Binding Presence.PresenceBrush}" Grid.RowSpan="1" StrokeThickness="1" Stretch="Uniform"  Fill="{Binding Presence.PresenceBrush}" Grid.Column="0" Grid.Row="0" />
                <Image VerticalAlignment="Top" Grid.Column="0" Grid.Row="0" Grid.RowSpan="1" Margin="4" Source="{Binding Avatar}" Stretch="Uniform" />


                        <!--<Button Style="{DynamicResource ButtonSurface}"  
                             VerticalContentAlignment="Stretch" x:Name="HyperlinkRosterItem" Click="HyperlinkRosterItem_Click" >
                            <Button.ContextMenu>
                                <ContextMenu >
                                    <MenuItem Header="Options">
                                        <MenuItem x:Name="MenuItemSubscribe" Click="MenuItemSubscribe_Click" Header="Subscribe" />
                                        <MenuItem x:Name="MenuItemUnsubscribe" Click="MenuItemUnsubscribe_Click" Header="Unsubscribe" />
                                    </MenuItem>
                                </ContextMenu>
                            </Button.ContextMenu>

                        <Button.Content>-->
                    <Grid Grid.Row="0" Grid.Column="1" Margin="0,0" Background="{DynamicResource ButtonBrush}" >
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="35" />
                                    <RowDefinition Height="70*" />
                                </Grid.RowDefinitions>

                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="200*" />
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="40" />
                            </Grid.ColumnDefinitions>
                                
                                <local:DialogControl Grid.Row="1" GotFocus="DialogControlLastMessage_GotFocus" Grid.ColumnSpan="7" BorderBrush="{x:Null}" Foreground="{x:Null}" Background="{x:Null}" x:Name="DialogControlLastMessage" Height="50"/>



                    <Button x:Name="ButtonRosterItem" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalAlignment="Stretch" Click="ButtonRosterItem_Click"  Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"  >
                        <TextBlock Grid.Row="0" Grid.Column="0" Margin="10,0,0,0" HorizontalAlignment="Stretch" TextTrimming="CharacterEllipsis"><Run Text="{Binding Name}" FontSize="16" FontWeight="Bold"/><Run Text=" "/><Run Text="-" /><Run Text=" "/><Run Text="{Binding Presence.Status}" /><LineBreak /><Run Text="{Binding TuneString}" FontSize="10"  /></TextBlock>
                    </Button>

                    <!--<Popup IsOpen="{Binding RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}, Path=IsSelected}" 
                           HorizontalAlignment="Right" VerticalAlignment="Top"  VerticalOffset="-35"
                           PlacementTarget="{Binding ElementName=ButtonRosterItem}" PopupAnimation="Fade" >-->
                    <Grid Background="{DynamicResource ButtonBrush}" Grid.Column="1"  x:Name="GridChatQuickButtons" Visibility="{Binding IsSelected, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}" >
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="35" />
                            <ColumnDefinition Width="35" />
                            <ColumnDefinition Width="35" />
                            <ColumnDefinition Width="35" />
                            <ColumnDefinition Width="35" />
                            <ColumnDefinition Width="35" />
                            <ColumnDefinition Width="35" />
                        </Grid.ColumnDefinitions>

                        <Button Grid.Column="0" Visibility="{Binding GeoVisible}" HorizontalAlignment="Stretch" Click="ButtonViewMap_Click2" Width="30" Height="30"  RenderTransformOrigin=".5,.5" VerticalAlignment="Stretch"  HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"  Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" x:Name="ButtonGlobe" ToolTip="Show location" >
                            <Button.RenderTransform>
                                <TransformGroup>
                                    <ScaleTransform/>
                                    <SkewTransform/>
                                    <RotateTransform/>
                                    <TranslateTransform/>
                                </TransformGroup>
                            </Button.RenderTransform>
                            <Rectangle Stretch="UniformToFill" Fill="{DynamicResource globe}" Width="24" Height="24" />
                        </Button>

                        <Button Width="24" Height="24" Grid.Column="1" HorizontalAlignment="Stretch" RenderTransformOrigin=".5,.5" Click="ButtonStartAudio_Click" VerticalAlignment="Stretch"  HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"  Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" x:Name="ButtonStartAudio" ToolTip="Start an Audio Call with this chap" >
                            <Button.RenderTransform>
                                <TransformGroup>
                                    <ScaleTransform/>
                                    <SkewTransform/>
                                    <RotateTransform/>
                                    <TranslateTransform/>
                                </TransformGroup>
                            </Button.RenderTransform>
                            <Rectangle Stretch="Uniform" Fill="{DynamicResource speaker}" />
                        </Button>

                        <Button Width="24" Height="24" Grid.Column="2" HorizontalAlignment="Stretch" RenderTransformOrigin=".5,.5" Click="ButtonStartVideo_Click" VerticalAlignment="Stretch"  HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"  Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" x:Name="ButtonStartVideo" ToolTip="Start aa video call" >
                            <Button.RenderTransform>
                                <TransformGroup>
                                    <ScaleTransform/>
                                    <SkewTransform/>
                                    <RotateTransform/>
                                    <TranslateTransform/>
                                </TransformGroup>
                            </Button.RenderTransform>
                            <Rectangle Stretch="Uniform" Fill="{DynamicResource videocamera}" />
                        </Button>

                        <Button Width="24" Height="24" Grid.Column="3" HorizontalAlignment="Stretch" RenderTransformOrigin=".5,.5" Click="ButtonSendFromCamera_Click"  VerticalAlignment="Stretch"  HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"  Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" x:Name="ButtonSendFromCamera" ToolTip="Send a PIC from the camera" >
                            <Button.RenderTransform>
                                <TransformGroup>
                                    <ScaleTransform/>
                                    <SkewTransform/>
                                    <RotateTransform/>
                                    <TranslateTransform/>
                                </TransformGroup>
                            </Button.RenderTransform>
                            <Rectangle Stretch="Uniform" Fill="{DynamicResource camera}" />
                        </Button>

                        <Button Width="24" Height="24" Grid.Column="4" HorizontalAlignment="Stretch" RenderTransformOrigin=".5,.5" Click="ButtonSendFile_Click"  VerticalAlignment="Stretch"  HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"  Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" x:Name="ButtonSendFile" ToolTip="Send a File" >
                            <Button.RenderTransform>
                                <TransformGroup>
                                    <ScaleTransform/>
                                    <SkewTransform/>
                                    <RotateTransform/>
                                    <TranslateTransform/>
                                </TransformGroup>
                            </Button.RenderTransform>
                            <Rectangle Stretch="Uniform" Fill="{DynamicResource folder}" />
                        </Button>

                        <Button Width="24" Height="24" Grid.Column="5" HorizontalAlignment="Stretch" RenderTransformOrigin=".5,.5" Click="ButtonSendScreenCapture_Click"  VerticalAlignment="Stretch"  HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"  Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" x:Name="ButtonSendScreenCapture" ToolTip="Send a screen capture" >
                            <Button.RenderTransform>
                                <TransformGroup>
                                    <ScaleTransform/>
                                    <SkewTransform/>
                                    <RotateTransform/>
                                    <TranslateTransform/>
                                </TransformGroup>
                            </Button.RenderTransform>
                            <Rectangle Stretch="Uniform" Fill="{DynamicResource crop}" />
                        </Button>


                    </Grid>
                        
                    <!--</Popup>-->
                    <Button Width="30" Height="30" Grid.Column="2" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"  RenderTransformOrigin=".5,.5" Visibility="{Binding NewMessagesVisible}" x:Name="ToggleButtonChat" Click="HyperlinkRosterItem_Click" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalAlignment="Stretch" VerticalContentAlignment="Stretch" >
                        <Button.RenderTransform>
                            <TransformGroup>
                                <ScaleTransform/>
                                <SkewTransform/>
                                <RotateTransform/>
                                <TranslateTransform/>
                            </TransformGroup>
                        </Button.RenderTransform>
                        <Rectangle Stretch="UniformToFill"  Width="24" Height="24">
                            <Rectangle.Fill>
                                <DrawingBrush Stretch="Fill">
                                    <DrawingBrush.Drawing>
                                        <DrawingGroup>
                                            <GeometryDrawing Geometry="F1 M 64,8C 94.9279,8 120,33.0721 120,64C 120,94.9279 94.9279,120 64,120C 33.0721,120 8,94.9279 8,64C 8,33.0721 33.0721,8 64,8 Z ">
                                                <GeometryDrawing.Brush>
                                                    <RadialGradientBrush RadiusX="0.5" RadiusY="0.5" Center="0.551282,0.448718" GradientOrigin="0.551282,0.448718">
                                                        <RadialGradientBrush.RelativeTransform>
                                                            <TransformGroup/>
                                                        </RadialGradientBrush.RelativeTransform>
                                                        <GradientStop Color="#FFA1E5FF" Offset="0"/>
                                                        <GradientStop x:Name="GradientStop2" Color="#FF50A0D3" Offset="0.567442"/>
                                                        <GradientStop Color="#FF005CA7" Offset="1"/>
                                                    </RadialGradientBrush>
                                                </GeometryDrawing.Brush>

                                            </GeometryDrawing>
                                            <GeometryDrawing Brush="#FF000000" Geometry="F1 M 50.8335,38.3543L 77.1665,38.3543C 85.4508,38.3543 92.1665,45.0701 92.1665,53.3543L 92.1665,65.8541C 92.1665,73.1257 86.9922,79.1889 80.1247,80.5625L 83.5832,95.6457L 67.4874,80.8541L 50.8335,80.8541C 42.5492,80.8541 35.8335,74.1384 35.8335,65.8541L 35.8335,53.3543C 35.8335,45.0701 42.5492,38.3543 50.8335,38.3543 Z "/>
                                        </DrawingGroup>
                                    </DrawingBrush.Drawing>
                                </DrawingBrush>
                            </Rectangle.Fill>
                            <Rectangle.Triggers>
                                <EventTrigger RoutedEvent="FrameworkElement.Loaded">
                                    <BeginStoryboard>
                                        <Storyboard RepeatBehavior="Forever">
                                            <DoubleAnimation 
                                                        Storyboard.TargetName="GradientStop2"
                                                        Storyboard.TargetProperty="Offset"
                                                        From="0.1" To="0.8" Duration="0:0:1.5"
                                                        AutoReverse="True" />
                                        </Storyboard>
                                    </BeginStoryboard>
                                </EventTrigger>
                            </Rectangle.Triggers>
                        </Rectangle>
                    </Button>

                </Grid>
                        <!--</Button.Content>

                    </Button>-->

                    


                <!--<s:ElementMenu>
                        <s:ElementMenuItem x:Name="MenuItemQuery" Click="MenuItemQuery_Click">Query</s:ElementMenuItem>
                    </s:ElementMenu>-->
              
                
                <Grid Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" x:Name="GridMoreUserOptions"  Visibility="Collapsed">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="30" />
                    </Grid.RowDefinitions>

                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="0" />
                        <ColumnDefinition Width="300*" />
                    </Grid.ColumnDefinitions>
                    
                    <Grid.RenderTransform>
                        <TranslateTransform X="0" Y="0" />
                    </Grid.RenderTransform>

                    <Grid Grid.Row="0" Grid.Column="1">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="80*" />
                            <ColumnDefinition Width="24" />
                            <ColumnDefinition Width="24" />
                        </Grid.ColumnDefinitions>
                        <TextBox Grid.Column="0"  x:Name="TextBoxChatToSend" GotFocus="TextBoxChatToSend_GotFocus" PreviewKeyDown="TextBoxChatToSend_PreviewKeyDown"/>
                        <Button Style="{DynamicResource ButtonSurface}"  ToolTip="Send Message" Grid.Column="1"  x:Name="ButtonSend" Click="ButtonSend_Click" >
                            <Image Width="20" Height="20" Source="Images/mail.png" />
                        </Button>
                        <Button Style="{DynamicResource ButtonSurface}" ToolTip="Clear" Grid.Column="2" x:Name="ButtonClearMessages" Click="ButtonClearMessages_Click" >
                            <Image Source="Images/trash.png" Width="20" Height="20" />
                        </Button>

                    </Grid>
                    
                   <!-- <extra:AudioViewerControl Grid.Row="1" Grid.Column="0"/> -->

                  
                </Grid>
                <!--<Rectangle x:Name="RectangleDarken" Grid.RowSpan="2" Grid.ColumnSpan="4" Fill="Black" Visibility="Visible" Opacity=".35" />-->



            </Grid>

            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorLevel=1, AncestorType={x:Type ListBoxItem}, Mode=FindAncestor}}" Value="True">
                    <!--<DataTrigger Binding="{Binding ElementName=ButtonExpandChat, Path=IsChecked}" Value="True">-->
                        <DataTrigger.EnterActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation Storyboard.TargetName="GridMoreUserOptions" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.Y)"  From="-48" To="0" DecelerationRatio="0.5" Duration="0:0:0.1"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </DataTrigger.EnterActions>
                    <Setter Property="Visibility" Value="Visible" TargetName="GridMoreUserOptions" />
                    <Setter Property="Height" Value="120" TargetName="DialogControlLastMessage" />
                    <Setter Property="Background" Value="White" TargetName="DialogControlLastMessage" />
                    <!--<Setter Property="Visibility" Value="Collapsed" TargetName="RectangleDarken" />-->
                </DataTrigger>
                <DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorLevel=1, AncestorType={x:Type ListBoxItem}, Mode=FindAncestor}}" Value="False">
                    <Setter Property="Visibility" Value="Collapsed" TargetName="GridMoreUserOptions" />
                    <Setter Property="Height" Value="50" TargetName="DialogControlLastMessage" />
                    <!--<Setter Property="Visibility" Value="Visible" TargetName="RectangleDarken" />-->
                </DataTrigger>
            </DataTemplate.Triggers>
            
        </DataTemplate>
    
        <Style x:Key="BorderStyle1" TargetType="{x:Type Border}">
        	<Setter Property="BorderBrush">
        		<Setter.Value>
        			<RadialGradientBrush>
        				<GradientStop Color="#FF136814" Offset="1"/>
        				<GradientStop Color="#FFA5EBA6" Offset="0"/>
        			</RadialGradientBrush>
        		</Setter.Value>
        	</Setter>
        </Style>


        <CollectionViewSource x:Key="SortedRosterItems" x:Name="OurSortedRosterCollection">
            <CollectionViewSource.SortDescriptions>
                <comp:SortDescription PropertyName="Name" />
            </CollectionViewSource.SortDescriptions>
            <CollectionViewSource.GroupDescriptions>
                <PropertyGroupDescription PropertyName="Group" />
            </CollectionViewSource.GroupDescriptions>
        </CollectionViewSource>
    	<LinearGradientBrush x:Key="ToolBarTrayBackground" EndPoint="688,0" MappingMode="Absolute" StartPoint="0,0">
    		<GradientStop Color="#F4F4F4" Offset="0"/>
    		<GradientStop Color="#FDFDFD" Offset="1"/>
    	</LinearGradientBrush>
    	<Style x:Key="ToolBarTrayStyle1" TargetType="{x:Type ToolBarTray}">
    		<Setter Property="Background" Value="{StaticResource ToolBarTrayBackground}"/>
    		<Style.Triggers>
    			<DataTrigger Binding="{Binding Source={x:Static SystemParameters.HighContrast}}" Value="true">
    				<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
    			</DataTrigger>
    		</Style.Triggers>
    	</Style>
    	<LinearGradientBrush x:Key="ToolBarHorizontalBackground" EndPoint="0,1" StartPoint="0,0">
    		<GradientStop Color="#FFFFFF" Offset="0"/>
    		<GradientStop Color="#FFFBFF" Offset="0.5"/>
    		<GradientStop Color="#F7F7F7" Offset="1"/>
    	</LinearGradientBrush>
    	<LinearGradientBrush x:Key="ToolBarToggleButtonVerticalBackground" EndPoint="1,0" StartPoint="0,0">
    		<GradientStop Color="#ECECEC" Offset="0"/>
    		<GradientStop Color="#DDDDDD" Offset="0.5"/>
    		<GradientStop Color="#A0A0A0" Offset="1"/>
    	</LinearGradientBrush>
    	<SolidColorBrush x:Key="ToolBarButtonHover" Color="#C2E0FF"/>
    	<SolidColorBrush x:Key="ToolBarGripper" Color="#C6C3C6"/>
    	<Style x:Key="ToolBarVerticalOverflowButtonStyle" TargetType="{x:Type ToggleButton}">
    		<Setter Property="Background" Value="{StaticResource ToolBarToggleButtonVerticalBackground}"/>
    		<Setter Property="MinHeight" Value="0"/>
    		<Setter Property="MinWidth" Value="0"/>
    		<Setter Property="Template">
    			<Setter.Value>
    				<ControlTemplate TargetType="{x:Type ToggleButton}">
    					<Border x:Name="Bd" Background="{TemplateBinding Background}" CornerRadius="0,0,3,3" SnapsToDevicePixels="true">
    						<Canvas HorizontalAlignment="Right" Height="6" Margin="2,7,2,2" SnapsToDevicePixels="true" VerticalAlignment="Bottom" Width="7">
    							<Path Data="M 1.5 1 L 1.5 6" Stroke="White"/>
    							<Path Data="M 0.5 0 L 0.5 5" Stroke="{TemplateBinding Foreground}"/>
    							<Path Data="M 3.5 0.5 L 7 3.5 L 4 6.5 Z" Fill="White"/>
    							<Path Data="M 3 -0.5 L 6 2.5 L 3 5.5 Z" Fill="{TemplateBinding Foreground}"/>
    						</Canvas>
    					</Border>
    					<ControlTemplate.Triggers>
    						<Trigger Property="IsMouseOver" Value="true">
    							<Setter Property="Background" TargetName="Bd" Value="{StaticResource ToolBarButtonHover}"/>
    						</Trigger>
    						<Trigger Property="IsKeyboardFocused" Value="true">
    							<Setter Property="Background" TargetName="Bd" Value="{StaticResource ToolBarButtonHover}"/>
    						</Trigger>
    						<Trigger Property="IsEnabled" Value="false">
    							<Setter Property="Foreground" Value="{StaticResource ToolBarGripper}"/>
    						</Trigger>
    					</ControlTemplate.Triggers>
    				</ControlTemplate>
    			</Setter.Value>
    		</Setter>
    		<Style.Triggers>
    			<DataTrigger Binding="{Binding Source={x:Static SystemParameters.HighContrast}}" Value="true">
    				<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
    			</DataTrigger>
    		</Style.Triggers>
    	</Style>
    	<LinearGradientBrush x:Key="ToolBarVerticalBackground" EndPoint="1,0" StartPoint="0,0">
    		<GradientStop Color="#FFFFFF" Offset="0"/>
    		<GradientStop Color="#FFFBFF" Offset="0.5"/>
    		<GradientStop Color="#F7F7F7" Offset="1"/>
    	</LinearGradientBrush>
    	<LinearGradientBrush x:Key="ToolBarToggleButtonHorizontalBackground" EndPoint="0,1" StartPoint="0,0">
    		<GradientStop Color="#ECECEC" Offset="0"/>
    		<GradientStop Color="#DDDDDD" Offset="0.5"/>
    		<GradientStop Color="#A0A0A0" Offset="1"/>
    	</LinearGradientBrush>
    	<Style x:Key="ToolBarHorizontalOverflowButtonStyle" TargetType="{x:Type ToggleButton}">
    		<Setter Property="Background" Value="{StaticResource ToolBarToggleButtonHorizontalBackground}"/>
    		<Setter Property="MinHeight" Value="0"/>
    		<Setter Property="MinWidth" Value="0"/>
    		<Setter Property="Template">
    			<Setter.Value>
    				<ControlTemplate TargetType="{x:Type ToggleButton}">
    					<Border x:Name="Bd" Background="{TemplateBinding Background}" CornerRadius="0,3,3,0" SnapsToDevicePixels="true">
    						<Canvas HorizontalAlignment="Right" Height="7" Margin="7,2,2,2" SnapsToDevicePixels="true" VerticalAlignment="Bottom" Width="6">
    							<Path Data="M 1 1.5 L 6 1.5" Stroke="White"/>
    							<Path Data="M 0 0.5 L 5 0.5" Stroke="{TemplateBinding Foreground}"/>
    							<Path Data="M 0.5 4 L 6.5 4 L 3.5 7 Z" Fill="White"/>
    							<Path Data="M -0.5 3 L 5.5 3 L 2.5 6 Z" Fill="{TemplateBinding Foreground}"/>
    						</Canvas>
    					</Border>
    					<ControlTemplate.Triggers>
    						<Trigger Property="IsMouseOver" Value="true">
    							<Setter Property="Background" TargetName="Bd" Value="{StaticResource ToolBarButtonHover}"/>
    						</Trigger>
    						<Trigger Property="IsKeyboardFocused" Value="true">
    							<Setter Property="Background" TargetName="Bd" Value="{StaticResource ToolBarButtonHover}"/>
    						</Trigger>
    						<Trigger Property="IsEnabled" Value="false">
    							<Setter Property="Foreground" Value="{StaticResource ToolBarGripper}"/>
    						</Trigger>
    					</ControlTemplate.Triggers>
    				</ControlTemplate>
    			</Setter.Value>
    		</Setter>
    		<Style.Triggers>
    			<DataTrigger Binding="{Binding Source={x:Static SystemParameters.HighContrast}}" Value="true">
    				<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
    			</DataTrigger>
    		</Style.Triggers>
    	</Style>
    	<SolidColorBrush x:Key="ToolBarMenuBorder" Color="#808080"/>
    	<SolidColorBrush x:Key="ToolBarSubMenuBackground" Color="#FDFDFD"/>
    	<Style x:Key="ToolBarThumbStyle" TargetType="{x:Type Thumb}">
    		<Setter Property="Template">
    			<Setter.Value>
    				<ControlTemplate TargetType="{x:Type Thumb}">
    					<Border Background="Transparent" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="True">
    						<Rectangle>
    							<Rectangle.Fill>
    								<DrawingBrush TileMode="Tile" Viewbox="0,0,4,4" Viewport="0,0,4,4" ViewportUnits="Absolute" ViewboxUnits="Absolute">
    									<DrawingBrush.Drawing>
    										<DrawingGroup>
    											<GeometryDrawing Brush="White" Geometry="M 1 1 L 1 3 L 3 3 L 3 1 z"/>
    											<GeometryDrawing Brush="{StaticResource ToolBarGripper}" Geometry="M 0 0 L 0 2 L 2 2 L 2 0 z"/>
    										</DrawingGroup>
    									</DrawingBrush.Drawing>
    								</DrawingBrush>
    							</Rectangle.Fill>
    						</Rectangle>
    					</Border>
    					<ControlTemplate.Triggers>
    						<Trigger Property="IsMouseOver" Value="true">
    							<Setter Property="Cursor" Value="SizeAll"/>
    						</Trigger>
    					</ControlTemplate.Triggers>
    				</ControlTemplate>
    			</Setter.Value>
    		</Setter>
    	</Style>
    	<Style x:Key="ToolBarMainPanelBorderStyle" TargetType="{x:Type Border}">
    		<Setter Property="Margin" Value="0,0,11,0"/>
    		<Setter Property="CornerRadius" Value="3,3,3,3"/>
    		<Style.Triggers>
    			<DataTrigger Binding="{Binding Source={x:Static SystemParameters.HighContrast}}" Value="true">
    				<Setter Property="CornerRadius" Value="0,0,0,0"/>
    			</DataTrigger>
    		</Style.Triggers>
    	</Style>


    	<Style x:Key="ToolBarStyle1" TargetType="{x:Type ToolBar}">
    		<Setter Property="Background" Value="{StaticResource ToolBarHorizontalBackground}"/>
    		<Setter Property="Template">
    			<Setter.Value>
    				<ControlTemplate TargetType="{x:Type ToolBar}">
    					<Grid x:Name="Grid" Margin="3,1,1,1" SnapsToDevicePixels="true">
    						<Grid x:Name="OverflowGrid" HorizontalAlignment="Right">
    							<ToggleButton x:Name="OverflowButton" ClickMode="Press" FocusVisualStyle="{x:Null}" IsChecked="{Binding IsOverflowOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" IsEnabled="{TemplateBinding HasOverflowItems}" Style="{StaticResource ToolBarHorizontalOverflowButtonStyle}" Background="{x:Null}"/>
    							<Popup x:Name="OverflowPopup" AllowsTransparency="true" Focusable="false" IsOpen="{Binding IsOverflowOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom" StaysOpen="false">
    								<Microsoft_Windows_Themes:SystemDropShadowChrome x:Name="Shdw" Color="Transparent">
    									<Border x:Name="ToolBarSubMenuBorder" BorderBrush="{StaticResource ToolBarMenuBorder}" BorderThickness="1" RenderOptions.ClearTypeHint="Enabled" Background="{DynamicResource ButtonBrush}" >
    										<ToolBarOverflowPanel x:Name="PART_ToolBarOverflowPanel" KeyboardNavigation.DirectionalNavigation="Cycle" FocusVisualStyle="{x:Null}" Focusable="true" Margin="2" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" KeyboardNavigation.TabNavigation="Cycle" WrapWidth="200"/>
    									</Border>
    								</Microsoft_Windows_Themes:SystemDropShadowChrome>
    							</Popup>
    						</Grid>
    						<Border x:Name="MainPanelBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" Style="{StaticResource ToolBarMainPanelBorderStyle}">
    							<DockPanel KeyboardNavigation.TabIndex="1" KeyboardNavigation.TabNavigation="Local">
    								<Thumb x:Name="ToolBarThumb" Margin="-3,-1,0,0" Padding="6,5,1,6" Style="{StaticResource ToolBarThumbStyle}" Width="10"/>
    								<ContentPresenter x:Name="ToolBarHeader" ContentSource="Header" HorizontalAlignment="Center" Margin="4,0,4,0" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/>
    								<ToolBarPanel x:Name="PART_ToolBarPanel" IsItemsHost="true" Margin="0,1,2,2" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
    							</DockPanel>
    						</Border>
    					</Grid>
    					<ControlTemplate.Triggers>
    						<Trigger Property="IsOverflowOpen" Value="true">
    							<Setter Property="IsEnabled" TargetName="ToolBarThumb" Value="false"/>
    						</Trigger>
    						<Trigger Property="Header" Value="{x:Null}">
    							<Setter Property="Visibility" TargetName="ToolBarHeader" Value="Collapsed"/>
    						</Trigger>
    						<Trigger Property="ToolBarTray.IsLocked" Value="true">
    							<Setter Property="Visibility" TargetName="ToolBarThumb" Value="Collapsed"/>
    						</Trigger>
    						<Trigger Property="HasDropShadow" SourceName="OverflowPopup" Value="true">
    							<Setter Property="Margin" TargetName="Shdw" Value="0,0,5,5"/>
    							<Setter Property="SnapsToDevicePixels" TargetName="Shdw" Value="true"/>
    							<Setter Property="Color" TargetName="Shdw" Value="#71000000"/>
    						</Trigger>
    						<Trigger Property="Orientation" Value="Vertical">
    							<Setter Property="Margin" TargetName="Grid" Value="1,3,1,1"/>
    							<Setter Property="Style" TargetName="OverflowButton" Value="{StaticResource ToolBarVerticalOverflowButtonStyle}"/>
    							<Setter Property="Height" TargetName="ToolBarThumb" Value="10"/>
    							<Setter Property="Width" TargetName="ToolBarThumb" Value="Auto"/>
    							<Setter Property="Margin" TargetName="ToolBarThumb" Value="-1,-3,0,0"/>
    							<Setter Property="Padding" TargetName="ToolBarThumb" Value="5,6,6,1"/>
    							<Setter Property="Margin" TargetName="ToolBarHeader" Value="0,0,0,4"/>
    							<Setter Property="Margin" TargetName="PART_ToolBarPanel" Value="1,0,2,2"/>
    							<Setter Property="DockPanel.Dock" TargetName="ToolBarThumb" Value="Top"/>
    							<Setter Property="DockPanel.Dock" TargetName="ToolBarHeader" Value="Top"/>
    							<Setter Property="HorizontalAlignment" TargetName="OverflowGrid" Value="Stretch"/>
    							<Setter Property="VerticalAlignment" TargetName="OverflowGrid" Value="Bottom"/>
    							<Setter Property="Placement" TargetName="OverflowPopup" Value="Right"/>
    							<Setter Property="Margin" TargetName="MainPanelBorder" Value="0,0,0,11"/>
    							<Setter Property="Background" Value="{StaticResource ToolBarVerticalBackground}"/>
    						</Trigger>
    						<Trigger Property="IsEnabled" Value="false">
    							<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
    						</Trigger>
    					</ControlTemplate.Triggers>
    				</ControlTemplate>
    			</Setter.Value>
    		</Setter>
    		<Style.Triggers>
    			<DataTrigger Binding="{Binding Source={x:Static SystemParameters.HighContrast}}" Value="true">
    				<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
    			</DataTrigger>
    		</Style.Triggers>
    	</Style>


    </Window.Resources>
	<!--<Window.Effect>
        <BlurEffect RenderingBias="Quality" Radius="3" />
		<DropShadowEffect/>
	</Window.Effect>-->


    <Grid x:Name="LayoutRoot">
				
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>


        <Rectangle x:Name="RectangleBottomBevel" VerticalAlignment="Bottom" Grid.RowSpan="3" Height="5" HorizontalAlignment="Stretch">
	<Rectangle.Fill>
		<DrawingBrush >
			<DrawingBrush.Drawing>
				<DrawingGroup>
					<GeometryDrawing Geometry="F1 M 0,10L 300,10L 296.563,5.95959L 4.68778,5.96855L 0,10 Z ">
						<GeometryDrawing.Brush>
							<LinearGradientBrush StartPoint="0.431511,-0.0609483" EndPoint="0.431511,1.01155">
								<GradientStop Color="#00141414" Offset="0"/>
								<GradientStop Color="#55898989" Offset="0.8"/>
								<GradientStop Color="#A6008800" Offset="1"/>
							</LinearGradientBrush>
						</GeometryDrawing.Brush>
					</GeometryDrawing>
				</DrawingGroup>
			</DrawingBrush.Drawing>
		</DrawingBrush>
	</Rectangle.Fill>
	</Rectangle>
	
        <Rectangle x:Name="RectangleRightBevel" VerticalAlignment="Stretch" Grid.RowSpan="3" Width="5" HorizontalAlignment="Right" RenderTransformOrigin="0.5,0.5">
	<Rectangle.Fill>
		<DrawingBrush >
			<DrawingBrush.Drawing>
				<DrawingGroup>
					<GeometryDrawing Geometry="F1 M 10,300L 10,0L 5.95959,3.43726L 5.96855,295.312L 10,300 Z ">
						<GeometryDrawing.Brush>
							<LinearGradientBrush StartPoint="-0.0609482,0.568489" EndPoint="1.01155,0.568489">
								<GradientStop Color="#00141414" Offset="0"/>
								<GradientStop Color="#55898989" Offset="0.8"/>
								<GradientStop Color="#A6008800" Offset="1"/>
							</LinearGradientBrush>
						</GeometryDrawing.Brush>
					</GeometryDrawing>
				</DrawingGroup>
			</DrawingBrush.Drawing>
		</DrawingBrush>
	</Rectangle.Fill>
	</Rectangle>	
        
        <Rectangle x:Name="RectangleGreen" Stretch="Fill" Grid.RowSpan="3" StrokeThickness="2" >
        	<Rectangle.Effect>
        		<BlurEffect/>
        	</Rectangle.Effect>
            <Rectangle.Fill>
                <LinearGradientBrush StartPoint=".5,0" EndPoint=".5,1">
                	<GradientStop Color="#EEAAFF88" Offset="0"/>
                	<GradientStop Color="#EEDDFF66" Offset="1"/>
                </LinearGradientBrush>
            </Rectangle.Fill>
        </Rectangle>
       
        <Label Grid.RowSpan="3" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="96" OpacityMask="#08000000" FontWeight="Bold" Content="XMPP"/>
        
        <Rectangle x:Name="Rectangle" Stretch="Fill" Grid.RowSpan="3">
            <Rectangle.Fill>
                <LinearGradientBrush StartPoint="0,1" EndPoint="1,0">
                    <LinearGradientBrush.RelativeTransform>
                        <TransformGroup>
                            <ScaleTransform/>
                            <SkewTransform AngleY="0" AngleX="0"/>
                            <RotateTransform Angle="0"/>
                            <TranslateTransform X="0" Y="0"/>
                        </TransformGroup>
                    </LinearGradientBrush.RelativeTransform>
                	<GradientStop Color="#2532AF10" Offset="0"/>
                	<GradientStop x:Name="GradientStop1" Color="#3E50E911" Offset="0.263"/>
                	<GradientStop x:Name="GradientStop2" Color="#4F9477FF" Offset="0.5"/>
                	<GradientStop x:Name="GradientStop3" Color="#3F45F11D" Offset="0.771"/>
                	<GradientStop Color="#2E3CB109" Offset="0.995349"/>
                </LinearGradientBrush>
            </Rectangle.Fill>
          
        </Rectangle>

        <!--TitlePanel contains the name of the application and page title-->
        <Grid  Margin="10"  Grid.Row="0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="84" />
                    <ColumnDefinition Width="107*" />
                    <ColumnDefinition Width="150" />
            </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="34" />
                    <RowDefinition Height="34" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

            <Rectangle Width="56" Height="56" Fill="{Binding PresenceStatus.PresenceBrush}" Grid.RowSpan="2" />
            <Image Width="50" Height="50" Source="{Binding Avatar}" Grid.RowSpan="2" x:Name="ImageAvatar" MouseDown="ImageAvatar_MouseDown" />

            <ToggleButton  Width="10" Height="10" Grid.Row="1" HorizontalAlignment="Right" VerticalAlignment="Bottom" x:Name="ToggleButtonPresence" />

            <TextBlock Margin="10,0" x:Name="ApplicationTitle" FontWeight="Bold"  Text="{Binding XMPPState}" VerticalAlignment="Center" Grid.Column="1"  />

            <TextBlock Margin="10,0" x:Name="JID" Text="{Binding JID}" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="1" VerticalAlignment="Center" />

            <!--<Rectangle x:Name="RectangleConnect" Fill="{Binding ConnectedStateBrush}" Width="30" Height="30" Grid.Column="2" Margin="5,6" Grid.RowSpan="2" />-->

            <ToolBarTray ToolBarTray.IsLocked="True" HorizontalAlignment="Right"
                         x:Name="ToolBarOptions" Grid.RowSpan="2" Background="{x:Null}" Grid.Column="2" Style="{DynamicResource ToolBarTrayStyle1}">
                <ToolBar Band="1" BandIndex="1" Background="{x:Null}" Style="{DynamicResource ToolBarStyle1}">

                    <Button Style="{DynamicResource ButtonSurface}" Margin="5" ToolTip="Connect to Server" x:Name="HyperlinkConnect" Click="HyperlinkConnect_Click" Padding="0" HorizontalAlignment="Center"  VerticalAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Center">
                        <Border Width="32" Height="32" >
                            <Border.Style>
                                <Style>
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding Ready}" Value="False">
                                            <Setter Property="Border.Background" Value="{DynamicResource disconnected}" />
                                        </DataTrigger>
                                        <DataTrigger Binding="{Binding Ready}" Value="True">
                                            <Setter Property="Border.Background" Value="{DynamicResource connected}" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </Border.Style>
                        </Border>
                            <!--<Image x:Name="ImageConnect" Width="32" Height="32">
                                <Image.Style>
                                    <Style>
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding Ready}" Value="False">
                                                <Setter Property="Image.Source" Value="Images/connect.png" />
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Ready}" Value="True">
                                                <Setter Property="Image.Source" Value="Images/connected.png" />
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </Image.Style>
                            </Image>-->
                    </Button>

                    <Button Style="{DynamicResource ButtonSurface}" ToolBar.OverflowMode="Always" ToolTip="Add a Buddy" x:Name="ButtonAddBuddy" IsEnabled="False" Click="ButtonAddBuddy_Click" Padding="0" HorizontalAlignment="Center" VerticalAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Center">
                        <Image Source="Images/add.png" Width="30" Height="30" Margin="5" HorizontalAlignment="Center" VerticalAlignment="Center" />
                    </Button>

                    <Button Style="{DynamicResource ButtonSurface}" ToolBar.OverflowMode="Always" ToolTip="View Downloads" x:Name="ButtonTransfers" IsEnabled="True" Click="ButtonTransfers_Click"  Padding="0" HorizontalAlignment="Center" VerticalAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Center">
                        <Image Source="Images/file.png" Width="30" Height="30" Margin="5"  HorizontalAlignment="Center" VerticalAlignment="Center" />
                    </Button>
                    <Button Style="{DynamicResource ButtonSurface}" ToolBar.OverflowMode="Always" ToolTip="View Media Sessions" x:Name="ButtonMediaSessions" IsEnabled="True" Click="ButtonMediaSessions_Click"  Padding="0" HorizontalAlignment="Center" VerticalAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Center">
                        <Image Source="Images/volume.png" Width="30" Height="30" Margin="5"  HorizontalAlignment="Center" VerticalAlignment="Center" />
                    </Button>

                    <Button ToolBar.OverflowMode="Always" Width="40" Height="40" Margin="5" HorizontalAlignment="Center" VerticalAlignment="Center" RenderTransformOrigin=".5,.5" Click="ButtonOptions_Click"  
                            Background="{DynamicResource ButtonBrush}"
                            HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"  Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" x:Name="ButtonOptions" ToolTip="Set General Options" >
                        <Button.RenderTransform>
                            <TransformGroup>
                                <ScaleTransform/>
                                <SkewTransform/>
                                <RotateTransform/>
                                <TranslateTransform/>
                            </TransformGroup>
                        </Button.RenderTransform>
                        <Rectangle Width="28" Height="28" Stretch="UniformToFill" Fill="{DynamicResource tools}" />
                    </Button>

                    <Button Style="{DynamicResource ButtonSurface}" ToolTip="Minimize" x:Name="ButtonMinimize" Click="ButtonMinimize_Click"  HorizontalAlignment="Center" Padding="0" VerticalAlignment="Bottom" 
                                     HorizontalContentAlignment="Center" VerticalContentAlignment="Bottom">
                        <Rectangle Width="20" Height="5" Margin="5" Stretch="UniformToFill" Fill="#FF555555" Stroke="#FF555555" />
                    </Button>

                    <Button Style="{DynamicResource ButtonSurface}" ToolTip="Close" x:Name="ButtonClose" Click="ButtonClose_Click"  HorizontalAlignment="Center" Padding="0" VerticalAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Center">
                        <Image Source="Images/calculator - multiply.png" Width="30" Height="30" Margin="5" HorizontalAlignment="Center" VerticalAlignment="Center" />
                    </Button>

                    <CheckBox ToolBar.OverflowMode="Always" Margin="5"  x:Name="CheckBoxSHowAll" IsChecked="{Binding ShowAll}" Content="Show All"/>

                </ToolBar>


            </ToolBarTray>



            <Grid Grid.Row="2" Grid.ColumnSpan="3" x:Name="GridPresence" Visibility="{Binding IsChecked, Converter={StaticResource BooleanToVisibilityConverter}, ElementName=ToggleButtonPresence}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="100" />
                    <ColumnDefinition Width="107*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>

            <ComboBox Background="{x:Null}" Grid.Column="0" x:Name="ComboBoxPresence" IsEnabled="False" Foreground="{Binding PresenceStatus.PresenceBrush}"
                              Text="{Binding PresenceStatus.PresenceType, Mode=TwoWay, NotifyOnTargetUpdated=True}" VerticalAlignment="Center"
                              TargetUpdated="TextBox_TargetUpdated" FontSize="10">
                <ComboBoxItem Content="{x:Static phone:PresenceType.available}">
                    <ComboBoxItem.ContentTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <Ellipse Width="10" Height="10" >
                                    <Ellipse.Fill>
                                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                            <GradientStop Color="#FF000E0E" Offset="1"/>
                                            <GradientStop Color="#FF80FF80"/>
                                        </LinearGradientBrush>
                                    </Ellipse.Fill>
                                </Ellipse>
                                <Label Content="Available"/>
                            </StackPanel>
                        </DataTemplate>
                    </ComboBoxItem.ContentTemplate>
                </ComboBoxItem>

                <ComboBoxItem Content="{x:Static phone:PresenceType.unavailable}" >
                    <ComboBoxItem.ContentTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <Ellipse Width="10" Height="10" >
                                    <Ellipse.Fill>
                                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                            <GradientStop Color="#FF000E0E" Offset="1"/>
                                            <GradientStop Color="Purple"/>
                                        </LinearGradientBrush>
                                    </Ellipse.Fill>
                                </Ellipse>
                                <Label Content="Unavailable"/>
                            </StackPanel>
                        </DataTemplate>
                    </ComboBoxItem.ContentTemplate>
                </ComboBoxItem>
            </ComboBox>

            <TextBox x:Name="TextBoxStatus" Margin="10,0" Background="{x:Null}" Grid.Column="1" Text="{Binding PresenceStatus.Status, Mode=TwoWay, NotifyOnTargetUpdated=True}" TargetUpdated="TextBox_TargetUpdated"/>

            <Button Style="{DynamicResource ButtonSurface}" ToolTip="Update Presence" Grid.Column="3" x:Name="ButtonSetStatus" IsEnabled="True" Click="ButtonSetStatus_Click"  Padding="0" HorizontalAlignment="Center" VerticalAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Center">
                <Image Source="Images/check.png" Width="20" Height="20" HorizontalAlignment="Center" VerticalAlignment="Center" />
            </Button>

            </Grid>
         

        </Grid>



        <!--<ListBox Grid.Row="2" Grid.ColumnSpan="5" x:Name="ListBoxRoster" 
                    BorderBrush="{x:Null}" Background="{x:Null}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch"
                     ItemsSource="{Binding RosterItems}" 
                     ItemTemplate="{StaticResource ChatMessageTemplate}" />-->

        <ListBox x:Name="ListBoxRoster" 
                 Grid.Row="1" Grid.ColumnSpan="5"
                 BorderBrush="{x:Null}" Background="{x:Null}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch"
                 ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                 SelectionChanged="ListBoxRoster_SelectionChanged"
                 SelectionMode="Multiple"
                 ItemsSource="{Binding Source={StaticResource SortedRosterItems}}"
                 ItemTemplate="{StaticResource ChatMessageTemplate}" >

       
            <ListBox.GroupStyle>
                <GroupStyle>
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <Grid>
                                <Rectangle x:Name="Rectangle" Stretch="Fill" >
                                    <Rectangle.Fill>
                                        <LinearGradientBrush StartPoint="0,.5" EndPoint="1,.5">
                                            <GradientStop Color="#00FF00FF" Offset="0"/>
                                            <GradientStop Color="#44FF00FF" Offset=".5"/>
                                            <GradientStop Color="#00FF00FF" Offset="1"/>
                                        </LinearGradientBrush>
                                    </Rectangle.Fill>
                                </Rectangle>
                                <TextBlock HorizontalAlignment="Center"  FontWeight="Bold" FontSize="12" Text="{Binding Name}" />
                            </Grid>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                </GroupStyle>
                <!--<x:Static Member="GroupStyle.Default"/>-->
            </ListBox.GroupStyle>

            <ListBox.ItemContainerStyle>
                <Style TargetType="{x:Type ListBoxItem}">
                    <Setter Property="FocusVisualStyle" Value="{x:Null}" />
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                <Border x:Name="Border" Padding="2"  SnapsToDevicePixels="true">
                                    <ContentPresenter />
                                </Border>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsSelected" Value="true">
                                        <Setter TargetName="Border" Property="Background" Value="{x:Null}"/>
                                        <Setter TargetName="Border" Property="BorderBrush" Value="Blue"/>
                                        <Setter TargetName="Border" Property="BorderThickness" Value="1,1,1,1"/>
                                    </Trigger>
                                    <Trigger Property="IsSelected" Value="false">
                                        <Setter TargetName="Border" Property="Background" Value="#66000000"/>
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                    
                    <Style.Triggers>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding Presence.IsOnline}" Value="False"  />
                                <Condition Binding="{Binding DataContext.ShowAll, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}"  Value="False"  />
                            </MultiDataTrigger.Conditions>
                            <Setter Property="Visibility" Value="Collapsed"/>
                        </MultiDataTrigger>

                        <DataTrigger Binding="{Binding DataContext.ShowAll, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}"  Value="True"  >
                            <Setter Property="Visibility" Value="Visible"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </ListBox.ItemContainerStyle>

        </ListBox>

    </Grid>
</Window>
